package com.p2p.controller.vipManagement;

import cn.hutool.core.bean.BeanUtil;
import com.p2p.common.DTO.InvestorsSelectDTO;
import com.p2p.common.R;
import com.p2p.common.base.RespResult;
import com.p2p.common.view.InvestorsVo;
import com.p2p.entity.Borrower;
import com.p2p.entity.Investors;
import com.p2p.service.vipManagementService.InvestorsService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/investors")
@Api(value = "投资用户API",tags = "会员管理中投资用户API")
public class InvestorsController {

    @Autowired
    private InvestorsService service;

    /**
     * 添加投资用户
     * @return R
     */
    @PostMapping("/addInvestors")
    @ApiOperation(value = "添加投资用户",notes = "添加投资用户",httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="成功"),
            @ApiResponse(code=400,message="代表参数格式不对"),
            @ApiResponse(code=404,message="代表找不到此请求"),
            @ApiResponse(code=500,message="代表后端代码出现异常"),
    })
    @ResponseBody
    public RespResult addInvestors(@RequestBody @ApiParam(name = "investors",value = "借贷用户实体Vo",required = true) InvestorsVo investorsVo){
        Investors investors = BeanUtil.copyProperties(investorsVo, Investors.class);
        return service.addInvestors(investors);
    }

    /**
     * 分页显示所有投资用户
     * @param currentPage 当前页码数默认第一页
     * @param pageSize 每页显示记录数
     * @return R
     */
    @ApiOperation(value = "分页显示所有投资用户",notes = "分页显示所有投资用户",
            httpMethod = "GET", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页码数默认第一页",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "pageSize",value = "每页显示记录数",paramType = "query",dataType = "String",required = false)
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @GetMapping(value = "/findInvestorsList")
    @ResponseBody
    public RespResult findInvestorsList(Integer currentPage,Integer pageSize ){
        return service.findInvestorsList(currentPage,pageSize);
    }



    /**
     * 修改投资用户信息
     * @return R
     */
    @ApiOperation(value = "修改投资用户信息",notes = "修改投资用户信息",
            httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @PostMapping(value = "/updateInvestors")
    @ResponseBody
    public RespResult updateInvestors(@RequestBody @ApiParam(name = "investorsVo",value = "借贷用户实体Vo",required = true) InvestorsVo investorsVo){
        Investors investors = BeanUtil.copyProperties(investorsVo, Investors.class);
        return service.updateInvestors(investors);
    }

    /**
     * 根据id回显投资用户信息
     * @return R
     */
    @ApiOperation(value = "根据id回显投资用户信息",notes = "根据id回显投资用户信息",
            httpMethod = "GET", response = R.class)
    @ApiImplicitParam(name = "id",value = "投资用户id",paramType = "query",dataType = "String",required = true)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @GetMapping(value = "/findInvestorsById")
    @ResponseBody
    public RespResult findInvestorsById(Long id){
        return service.findInvestorsById(id);
    }


    /**
     * 根据id修改投资用户密码
     * @return R
     */
    @ApiOperation(value = "根据id修改投资用户密码",notes = "根据id修改投资用户密码",
            httpMethod = "POST", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "投资用户id",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "loginPwd",value = "登录密码",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "payPwd",value = "支付密码",paramType = "query",dataType = "String",required = false)
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @PostMapping (value = "/updateInvestorsPwdById")
    @ResponseBody
    public RespResult updateInvestorsPwdById(Long id,String loginPwd,String payPwd){
        return service.updateInvestorsPwdById(id,loginPwd,payPwd);
    }



    /**
     * 更据条件查询分页显示所有投资用户

     * @return R
     */
    @ApiOperation(value = "更据条件查询分页显示所有投资用户",notes = "更据条件查询分页显示所有投资用户",
            httpMethod = "GET", response = R.class)

    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @GetMapping(value = "/findInvestorsByCondition")
    @ResponseBody
    public RespResult findInvestorsByCondition(@RequestBody InvestorsSelectDTO investorsSelectDTO){
        return service.findInvestorsByCondition(investorsSelectDTO);
    }



    /**
     * 根据id删除投资用户信息
     * @return R
     */
    @ApiOperation(value = "根据id删除投资用户信息",notes = "根据id删除投资用户信息",
            httpMethod = "POST", response = R.class)
    @ApiImplicitParam(name = "id",value = "投资用户id",paramType = "query",dataType = "String",required = true)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @PostMapping (value = "/delInvestorsById")
    @ResponseBody
    public RespResult delInvestorsById(Long id){
        return service.delInvestorsById(id);
    }




}
